
#ifndef  RECOVERY_TOPIC_H
#define  RECOVERY_TOPIC_H

#include "recovery/ITopic.h"
#include <memory>
namespace recovery {

namespace log {
    class ILog;
}

struct TopicOption {
public:
    TopicOption();
    ~TopicOption();
public:
    std::string logSuffix;
    std::string directory;
};

class Topic : public ITopic<Topic> {
public:
    Topic(const std::string & name, const TopicOption &  option);
    ~Topic() override;

    int open() override;
    int close() override;
	bool isOpen() const override{
		return opened;
	}

    //interface ???? Error Info  ?????
    // only memory operation 
    Topic & begin() override ;
    Topic & set(const std::string & key, const std::string & value) override ;
    Topic & commit() override ; // do real job
    Topic & rollback() override ; // do real job
    typedef const std::function<int (const std::string & , const std::string &)> KeyValueFunction ;
	int visit(KeyValueFunction & fn) override ;

private:
    std::string name;
    TopicOption _option;
    bool opened;

    std::unique_ptr<recovery::log::ILog> log;

};

}// end of namespace recovery

#endif   /* RECOVERY_TOPIC_H */
